package wyj;

import java.util.Scanner;

class Main1234 {
    public  static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int m,xs,i,cd,c;
        String x;
        c=0;
        x="";
        m = in.nextInt();
        cd=m;
        int[] a = new int[m+1];
        xs=in.nextInt();
        while (c!=2){
            a[m]=a[m]+xs;
            m=in.nextInt();
            xs=in.nextInt();
            if (m==0){
                c++;
            }
        }
        a[m]=a[m]+xs;
        for (i=cd;i>0;i--){
            if (a[i]!=0){
                if (i==1){
                    x=x+a[i]+"x"+"+";
                }
                else{
                    x=x+a[i]+"x"+i+"+";
                }
            }
        }
        System.out.println(x+a[0]);

    }
}
